<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{html_radios}</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.custom.functions.html" title="Chapter 8. Custom Functions">
<link rel="prev" href="language.function.html.options.html" title="{html_options}">
<link rel="next" href="language.function.html.select.date.html" title="{html_select_date}">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">{html_radios}</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.function.html.options.html">Prev</a> </td>
<th width="60%" align="center">Chapter 8. Custom Functions</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.html.select.date.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="{html_radios}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.html.radios"></a>{html_radios}</h2></div></div></div>
<p>
   <code class="varname">{html_radios}</code> is a
   <a class="link" href="language.custom.functions.html" title="Chapter 8. Custom Functions">custom function</a>
   that creates a HTML radio button group.
   It also takes care of which item is selected by default as well.
   </p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Attribute Name</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">name</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>radio</em></span></td>
<td>Name of radio list</td>
</tr>
<tr>
<td align="center">values</td>
<td align="center">array</td>
<td align="center">Yes, unless using options attribute</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>An array of values for radio buttons</td>
</tr>
<tr>
<td align="center">output</td>
<td align="center">array</td>
<td align="center">Yes, unless using options attribute</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>An array of output for radio buttons</td>
</tr>
<tr>
<td align="center">selected</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>empty</em></span></td>
<td>The selected radio element</td>
</tr>
<tr>
<td align="center">options</td>
<td align="center">associative array</td>
<td align="center">Yes, unless using values and output</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>An associative array of values and output</td>
</tr>
<tr>
<td align="center">separator</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>empty</em></span></td>
<td>String of text to separate each radio item</td>
</tr>
<tr>
<td align="center">assign</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>empty</em></span></td>
<td>Assign radio tags to an array instead of output</td>
</tr>
<tr>
<td align="center">labels</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td>
<td>Add &lt;label&gt;-tags to the output</td>
</tr>
<tr>
<td align="center">label_ids</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em><code class="constant">FALSE</code></em></span></td>
<td>Add id-attributes to &lt;label&gt; and &lt;input&gt; to the output</td>
</tr>
<tr>
<td align="center">escape</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td>
<td>Escape the output / content (values are always escaped)</td>
</tr>
</tbody>
</table></div>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
    Required attributes are <em class="parameter"><code>values</code></em> and
    <em class="parameter"><code>output</code></em>,  unless you use <em class="parameter"><code>options</code></em>
    instead.
    </p></li>
<li class="listitem"><p>
    All output is XHTML compliant.
    </p></li>
<li class="listitem"><p>
      All parameters that are not in the list above are output as
      name/value-pairs inside each of the created
      <code class="literal">&lt;input&gt;</code>-tags.
     </p></li>
</ul></div>
<div class="example">
<a name="id398708"></a><p class="title"><b>Example 8.13. {html_radios} first example</b></p>
<div class="example-contents">
<pre class="programlisting">

&lt;?php

$smarty-&gt;assign('cust_ids', array(1000,1001,1002,1003));
$smarty-&gt;assign('cust_names', array(
                              'Joe Schmoe',
                              'Jack Smith',
                              'Jane Johnson',
                              'Charlie Brown')
                              );
$smarty-&gt;assign('customer_id', 1001);

?&gt;

  </pre>
<p>
   Where template is:
  </p>
<pre class="programlisting">

{html_radios name='id' values=$cust_ids output=$cust_names
       selected=$customer_id separator='&lt;br /&gt;'}
   
  </pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id398740"></a><p class="title"><b>Example 8.14. {html_radios} second example</b></p>
<div class="example-contents">
<pre class="programlisting">

&lt;?php

$smarty-&gt;assign('cust_radios', array(
                               1000 =&gt; 'Joe Schmoe',
                               1001 =&gt; 'Jack Smith',
                               1002 =&gt; 'Jane Johnson',
                               1003 =&gt; 'Charlie Brown'));
$smarty-&gt;assign('customer_id', 1001);

?&gt;

  </pre>
<p>
   Where template is:
  </p>
<pre class="programlisting">

{html_radios name='id' options=$cust_radios
     selected=$customer_id separator='&lt;br /&gt;'}

  </pre>
<p>
   Both examples will output:
  </p>
<pre class="screen">

&lt;label&gt;&lt;input type="radio" name="id" value="1000" /&gt;Joe Schmoe&lt;/label&gt;&lt;br /&gt;
&lt;label&gt;&lt;input type="radio" name="id" value="1001" checked="checked" /&gt;Jack Smith&lt;/label&gt;&lt;br /&gt;
&lt;label&gt;&lt;input type="radio" name="id" value="1002" /&gt;Jane Johnson&lt;/label&gt;&lt;br /&gt;
&lt;label&gt;&lt;input type="radio" name="id" value="1003" /&gt;Charlie Brown&lt;/label&gt;&lt;br /&gt;

  </pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id398779"></a><p class="title"><b>Example 8.15. {html_radios} - Database example (eg PEAR or ADODB):</b></p>
<div class="example-contents">
<pre class="programlisting">

&lt;?php

$sql = 'select type_id, types from contact_types order by type';
$smarty-&gt;assign('contact_types',$db-&gt;getAssoc($sql));

$sql = 'select contact_id, name, email, contact_type_id '
        .'from contacts where contact_id='.$contact_id;
$smarty-&gt;assign('contact',$db-&gt;getRow($sql));

?&gt;

  </pre>
<p>
   The variable assigned from the database above
   would be output with the template:
  </p>
<pre class="programlisting">

{html_radios name='contact_type_id' options=$contact_types
     selected=$contact.contact_type_id separator='&lt;br /&gt;'}

  </pre>
</div>
</div>
<br class="example-break"><p>
  See also <a class="link" href="language.function.html.checkboxes.html" title="{html_checkboxes}"><code class="varname">{html_checkboxes}</code></a>
  and <a class="link" href="language.function.html.options.html" title="{html_options}"><code class="varname">{html_options}</code></a>
 </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.function.html.options.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.custom.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.html.select.date.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">{html_options} </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {html_select_date}</td>
</tr>
</table>
</div>
</body>
</html>
